package TableHelpers;

import SQLAPI.WebUser;
import SQLAPI.SQL;
import java.util.ArrayList;

/**
 *This class is used solely for building an HTML table from information in the 
 * web_user table.
 * @author Scott Catsirelis - 602705
 */
public class WebUserTable {

    private final SQL sql = new SQL();

    public WebUserTable() {
    }
    
    /**
     * Returns a String containing the text to build an HTML table containing
     * all of the web users in the database web_user table.
     * @return 
     */
    public String createTable() {
        ArrayList<String> headerList = sql.getWebUserHeaders();
        String table = "<thead><tr>";
        for (int i = 0; i < headerList.size(); i++) {

            table += "<th>" + headerList.get(i) + "</th>";
        }
        table += "<th>view reports</th>";
        table += "</tr></thead>";
        table += "<tbody>";
        
        ArrayList<WebUser> list = sql.getWebUsers();
        for (int i = 0; i < list.size(); i++) {
            WebUser e = list.get(i);
            table += "<tr>";
            table += "<td>" + e.getEmpid() + "</td>";
            table += "<td>" + e.getEmail() + "</td>";
            table += "<td>**********</td>";
            
            if(e.getStatus()==1) 
                table += "<td>Online</td>";
            
            if(e.getStatus()==0)
                table += "<td>Offline</td>";
            
            table += "<td><button type=\"button\" class=\"btn btn-primary btn-xs\" onclick=\"location.href=\'employeeReports.jsp?userid="+e.getEmpid()+"\'\">View Reports</button></td>";
            table += "</tr>";
        }
        table += "</tbody>";

        return table;
    }

}
